import { Row, Col, Button, Icon, Card, Breadcrumb } from 'antd';
import { connect } from 'react-redux';
import PropTypes from "prop-types";
import less from './index.less';


class PageNav extends React.Component {
  //利用PropTypes记住所跳转每个页面的位置 
  static contextTypes = {
    router: PropTypes.object
  }
  
  constructor(props, context) {
      super(props, context);
      this.state={
        pathSnippets:[]
      }
  }

  componentWillMount(){

  }
  

  componentWillReceiveProps(){ 
    //对路径进行切分，存放到this.state.pathSnippets中
    let pathSnippets = this.context.router.history.location.pathname.split('/').filter(i => i);
    this.setState({
      pathSnippets
    })
  }

  createBreadcrumb() {
    console.log(3);
    // console.log(this.props);
    let menuPath = this.props.menuPath;
    //   
    // return (<Breadcrumb.Item><a href="javascript:void(0)">Application List</a></Breadcrumb.Item>) 
    let breadcrumbList=[];
    let path='';
    const list= this.props.authMenuList;
    const pathSnippets=this.state.pathSnippets;
    for(let j=0;j<pathSnippets.length;j++){
      path +='/'+pathSnippets[j];
      for(let i=0;i<list.length;i++){
        if(list[i].path==path&&j==0){
          breadcrumbList.push(<Breadcrumb.Item >{list[i].title}</Breadcrumb.Item>);
        }else if(list[i].path==path){
          breadcrumbList.push(<Breadcrumb.Item ><a href="javascript:void(0)">{list[i].title}</a></Breadcrumb.Item>);
        }
      }
    }

    return breadcrumbList;
  }

  render() {
    const breadcrumbList=this.createBreadcrumb();
    const isShow=breadcrumbList.length>0?'block':'none';
    return (
      <div className={less.page_nav} style={{display:isShow}}>
        <Card bordered={false} bodyStyle={{ "padding": "10px 24px" }} className={less.card_wrapper}>
          <Breadcrumb separator=">">
            {breadcrumbList}
          </Breadcrumb>
        </Card>
      </div>
    )
  }
}

const mapStateToProps = state => {
  return {
    authMenuList: state.authMenuList,
    menuPath: state.menuPath
  }
}
export default connect(mapStateToProps)(PageNav);